 <template>
  <div style="height:100%">
    <div class="platform-detail">
      <el-header style="height:54px; padding:0">
        <div class="flex-auto">
          <my-header :collapse="collapse">
            <div :class="!collapse?'header-logo':'header-logo-hidden'">

              <div class="logo-flex">
                <img src="../../assets/platformDetail/logo.png"
                     style="width: 32px;height:fit-content;" />
              </div>
              <div class="name"
                   v-if="!collapse">
                建筑室内环境健康性能监测与预警系统
              </div>
            </div>
            <span @click="menuCollapse"
                  class="iconSize">
              <i v-if="!collapse"
                 class="el-icon-s-fold"></i>
              <i v-else
                 class="el-icon-s-unfold"></i>
            </span>
          </my-header>
        </div>
      </el-header>
      <div class="content">
        <div class="menuBox"
             :class="!collapse?'menuBox-expand':'menuBox-no-expand'"
             :style="`height:${menuH}px`">

          <el-menu class="el-menu-vertical-demo"
                   :default-active="activedIndex"
                   :router="true"
                   :collapse="collapse">
            <template v-for="item in menuList">
              <el-menu-item :key="item.path"
                            v-if="item.children == null"
                            :index="item.path">
                <i class="iconfont"
                   :class="item.meta.icon"></i>
                <template #title>{{ item.meta.title }}</template>
              </el-menu-item>
              <template v-else>
                <el-sub-menu :index="item.path"
                             :key="item.path">
                  <!-- <i :class="item.icon"></i> -->
                  <template #title>
                    <i class="iconfont"
                       :class="item.meta.icon"></i>
                    <span>{{ item.meta.title }}</span>
                  </template>
                  <el-menu-item :index="subItem.path"
                                v-for="subItem in item.children"
                                :key="subItem.path">
                    <i class="iconfont"
                       :class="subItem.icon"></i>
                    <template #title>{{ subItem.meta.title }}</template>
                  </el-menu-item>
                </el-sub-menu>
              </template>
            </template>
          </el-menu>
          <div style="padding:15px 0">
            <div class="logo-flex">
              <img src="../../assets/platformDetail/logo.png"
                   style="width: 35px" />
            </div>
            <div class="platform-name"
                 v-show="!collapse">
              {{name}}
            </div>
          </div>

        </div>

        <div class="rightBox"
             :style="`height:${contentH}px`">
          <el-main class="main">
            <router-view></router-view>
          </el-main>
        </div>
      </div>

    </div>
  </div>
</template>
<script>
import myHeader from "@/components/platformHeader";
import store from "@/store/modules/user"
import { getImg } from "@/api/common";
export default {
  name: "",
  components: {
    myHeader
  },
  data() {
    return {
      activedIndex: "",
      collapse: false,
      userInfo: store.state.userInfo,
      contentH: 0,
      menuH: 0,
      menuList: [
        {
          path: "/PMSPlatformDetail/home",
          meta: { title: "环境总况", icon: "icon-huanjing" }
        },
        {
          path: "/PMSPlatformDetail/deviceManage",
          meta: { title: "设备管理", icon: "icon-shebei" }
        }
      ],
      logo: '',
      logoUrl: "",
      name: "",
      platformId: ""
    };
  },
  mounted() {
    const _this = this;
    this.activedIndex = this.$route.path;
    this.contentH = document.documentElement.clientHeight - 59;
    this.menuH = document.documentElement.clientHeight - 80;
    window.addEventListener("resize", () => {
      this.contentH = document.documentElement.clientHeight - 59;
      this.menuH = document.documentElement.clientHeight - 80;
    });
    if (this.$route.query.platformId) {
      this.logo = this.$route.query.logo;
      this.platformId = this.$route.query.platformId;
      this.name = this.$route.query.name;
      for (let i = 0; i < this.menuList.length; i++) {
        const element = this.menuList[i];
        element.path = `${element.path}?logo=${this.logo}&name=${this.name}&platformId=${this.platformId}`
      }
    } else {
      var selectProject = JSON.parse(localStorage.getItem('selectProject'));
      _this.logo = selectProject.logo;
      _this.name = selectProject.name;
    }
    this.$nextTick(() => {
      let data = {
        key: _this.logo
      };
      if (_this.logo) {
        getImg(data).then(res => {
          if (res["code"] == 200) {
            _this.logoUrl = res.value;
          }
        });
      }
    })
  },
  watch: {
    $route(to, from) {
      this.activedIndex =
        "/" +
        this.$route.path.split("/")[1] +
        "/" +
        this.$route.path.split("/")[2];
    }
  },
  methods: {
    menuCollapse() {
      this.collapse = !this.collapse;
    }
  }
};
</script>
<style>

</style>
<style lang="scss" scoped>
.collapse-flex-box {
  width: 100%;
  color: #333;
  font-size: 24px;
}
.content {
  max-width: 100vw;
  display: flex;
  flex-direction: row;
  .menuBox {
    flex: none;
    width: 200px;
    .menu-logo-flex {
      font-family: "Microsoft YaHei";
      font-style: normal;
      font-weight: 700;
      font-size: 14px;
      line-height: 18px;
      text-align: center;
      color: #a7afb7;
    }
  }
  .rightBox {
    min-height: 100%;
    flex: 1 1 auto;
    .main {
      height: 0;
      flex: 1;
      min-height: 100%;
      box-sizing: border-box;
    }
  }
}
.header {
  line-height: 60px;
  border-bottom: 1px solid #e6ebf5;
  box-shadow: 0 2px 12px 0 rgb(0 0 0 / 10%);
}
.header-logo {
  width: 200px;
  display: flex;
  margin-right: 20px;
  .name {
    margin-left: 12px;
  }
}
.header-logo-hidden {
  width: 80px;
  display: flex;
  margin-right: 20px;
}
.menuBox {
  position: relative;
  overflow-y: scroll;
  padding: 12px;
  margin: 16px;
  border-radius: 4px;
  // background-color: rgb(40, 51, 62);
  background-color: #ffffff;
  .project-name {
    // color: #1890ff;
    height: 50px;
    font-size: 30px;
    text-align: center;
    line-height: 50px;
    font-weight: bold;
  }
  .bottom {
    padding: 15px;
    position: absolute;
    bottom: 0px;
    .name {
      text-align: center;
      margin-top: 10px;
      font-size: 14px;
      font-weight: 400;
      line-height: 19px;
      color: #636975;
    }
  }
}
.menuBox-expand {
  width: 200px;
  transition: width 0.5s;
}
.menuBox-no-expand {
  width: 64px;
  transition: width 0.5s;
}
.el-menu-vertical-demo .iconfont {
  margin-right: 10px;
}
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 200px;
  min-height: 400px;
}
.iconSize {
  font-size: 26px !important;
  line-height: 54px;
  display: flex;
  align-items: center;
}
.logo-flex {
  display: flex;
  justify-content: center;
  align-items: center;
}
.platform-name {
  margin-top: 10px;
  font-size: 16px;
  font-weight: 400;
  line-height: 40px;
  /*color: #fafafa;*/
  text-align: center;
}
@media screen and (max-width: 1440px) {
  .title {
    font-size: 14px;
    font-weight: bold;
    line-height: 21px;
    color: #0a0a0a;
  }
}
</style>
